package cn.iocoder.yudao.module.promotion.service.prizedraw;

import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.prizedraw.vo.PrizeDrawAwardsRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.prizedraw.PrizeDrawAwardsDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.prizedraw.PrizeDrawAwardsMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

/**
 * 抽奖活动奖品 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class PrizeDrawAwardsServiceImpl implements PrizeDrawAwardsService {

    @Resource
    private PrizeDrawAwardsMapper prizeDrawAwardsMapper;

    /**
     * 根据抽奖活动id获取奖品列表
     *
     * @param prizeDrawId
     * @return
     */
    @Override
    public List<PrizeDrawAwardsRespVO> getPrizeDrawAwardsListByPrizeDrawId(Long prizeDrawId) {
        List<PrizeDrawAwardsDO> prizeDrawAwardsDOS = prizeDrawAwardsMapper.selectList(new LambdaQueryWrapperX<PrizeDrawAwardsDO>()
                .eq(PrizeDrawAwardsDO::getPrizeDrawId, prizeDrawId).orderByAsc(PrizeDrawAwardsDO::getDrawSort));
        if (CollectionUtil.isEmpty(prizeDrawAwardsDOS)) {
            return null;
        }
        return BeanUtils.toBean(prizeDrawAwardsDOS, PrizeDrawAwardsRespVO.class);
    }

}